﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;

namespace 数据迁移工具
{
    public partial class ProcessLogForm : UIForm
    {
        public ProcessLogForm()
        {
            InitializeComponent();
        }

        public void UpdateProgressBar(int val)
        {
            this.Invoke(() =>
            {
                if (val == 100)
                    button1.Enabled = true;
                UProbar.Value = val;
            });

        }

        public void UpdateLogListBox(string line)
        {
            this.Invoke(() =>
            {
                LogListBox.Items.Add(line);
                if (LogListBox.Items.Count > 100)
                    LogListBox.Items.RemoveAt(0);
                ScrollToBottom();
            });
        }
        // 滚动到 UIListBox 底部
        private void ScrollToBottom()
        {
            // 设置 TopIndex 为最后一个项的索引
            if (LogListBox.Items.Count > 0)
            {
                LogListBox.TopIndex = LogListBox.Items.Count - 1;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
